<template>
<el-main>
  <el-input placeholder="请输入内容" v-model="keyword" clearable style="width:550px;"> </el-input>
  <el-button type="primary" style="background-color:#719CC6" @click="searchgoods()">搜索</el-button>
</el-main>
</template>

<script>
//导入json
import goods from '../assets/js/goods.json';
export default {
    data() {
      return {
      keyword: '',
      good:'', //存放1个商品对象
      goods:goods //存放全部商品
      }
    },
     methods:{
      searchgoods(){
        this.$router.push({path:'/noclear',query:{inp:this.keyword}});  //操作 路由跳转  query传参inp接收input框输入的关键词
      }
},
// 调用created钩子：实例已被创建
 created(){
    //利用query查询字符串获取当前商品的id
    let id=this.$route.query.id;
    //过滤goods，获取对应的id商品，返回
    let goodFilter=this.goods.filter(item=>item.id==id);
    //获取id对应的对象
    this.good=goodFilter[0];
  },
};
</script>

<style>
span{
    margin: auto;
}
</style>